home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / POST.TRM < prev    next >
Text File  |  1992-03-25  |  10KB  |  357 lines

  1. /*
  2.  * $Id: post.trm,v 3.26 92/03/24 22:35:40 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - post.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *     postscript
  25.  *
  26.  * AUTHORS
  27.  *  Russell Lang
  28.  * 
  29.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  30.  *
  31.  * The 'postscript' driver produces landscape output 10" wide and 7" high.  
  32.  * To change font to Times-Roman and font size to 20pts use 
  33.  * 'set term postscript "Times-Roman" 20'.
  34.  * To get a smaller (5" x 3.5") eps output use 'set term post eps'
  35.  * and make only one plot per file.  Font size for eps will be half
  36.  * the specified size.
  37.  */
  38.  
  39.  
  40. /* PostScript driver by Russell Lang, rjl@monu1.cc.monash.edu.au */
  41.  
  42. char ps_font[MAX_ID_LEN+1] = "Courier" ; /* name of font */
  43. int ps_fontsize = 14;                     /* size of font in pts */
  44. BOOLEAN ps_portrait = FALSE;                 /* vertical page */
  45. BOOLEAN ps_color = FALSE;
  46. BOOLEAN ps_eps = FALSE;    /* Is this for an eps file? */
  47.             /* Added by Robert Davis <davis@ecn.purdue.edu> */
  48. int ps_page=0;            /* page count */
  49. int ps_path_count=0;     /* count of lines in path */
  50. int ps_ang=0;            /* text angle */
  51. enum JUSTIFY ps_justify=LEFT;    /* text is flush left */
  52.  
  53. char *PS_header[] = {
  54. "/vpt2 vpt 2 mul def\n",
  55. "/hpt2 hpt 2 mul def\n",
  56. /* flush left show */
  57. "/Lshow { currentpoint stroke moveto\n",
  58. "  0 vshift rmoveto show } def\n", 
  59. /* flush right show */
  60. "/Rshow { currentpoint stroke moveto\n",
  61. "  dup stringwidth pop neg vshift rmoveto show } def\n", 
  62. /* centred show */
  63. "/Cshow { currentpoint stroke moveto\n",
  64. "  dup stringwidth pop -2 div vshift rmoveto show } def\n", 
  65. /* Dash or Color Line */
  66. "/DL { Color {setrgbcolor [] 0 setdash pop}\n",
  67. " {pop pop pop 0 setdash} ifelse } def\n",
  68. /* Border Lines */
  69. "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
  70. /* Axes Lines */
  71. "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
  72. /* Plot Lines */
  73. "/PL { stroke gnulinewidth setlinewidth } def\n",
  74. /* Line Types */
  75. "/LTb { BL [] 0 0 0 DL } def\n", /* border */
  76. "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
  77. "/LT0 { PL [] 0 1 0 DL } def\n",
  78. "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
  79. "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
  80. "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
  81. "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
  82. "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
  83. "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
  84. "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
  85. "/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
  86. "/M {moveto} def\n",
  87. "/L {lineto} def\n",
  88. "/P { stroke [] 0 setdash\n", /* Point */
  89. "  currentlinewidth 2 div sub moveto\n",
  90. "  0 currentlinewidth rlineto  stroke } def\n",
  91. "/D { stroke [] 0 setdash  2 copy  vpt add moveto\n", /* Diamond */
  92. "  hpt neg vpt neg rlineto  hpt vpt neg rlineto\n",
  93. "  hpt vpt rlineto  hpt neg vpt rlineto  closepath  stroke\n",
  94. "  P  } def\n",
  95. "/A { stroke [] 0 setdash  vpt sub moveto  0 vpt2 rlineto\n", /* Plus (Add) */
  96. "  currentpoint stroke moveto\n",
  97. "  hpt neg vpt neg rmoveto  hpt2 0 rlineto stroke\n",
  98. "  } def\n",
  99. "/B { stroke [] 0 setdash  2 copy  exch hpt sub exch vpt add moveto\n", /* Box */
  100. "  0 vpt2 neg rlineto  hpt2 0 rlineto  0 vpt2 rlineto\n",
  101. "  hpt2 neg 0 rlineto  closepath  stroke\n",
  102. "  P  } def\n",
  103. "/C { stroke [] 0 setdash  exch hpt sub exch vpt add moveto\n", /* Cross */
  104. "  hpt2 vpt2 neg rlineto  currentpoint  stroke  moveto\n",
  105. "  hpt2 neg 0 rmoveto  hpt2 vpt2 rlineto stroke  } def\n",
  106. "/T { stroke [] 0 setdash  2 copy  vpt 1.12 mul add moveto\n", /* Triangle */
  107. "  hpt neg vpt -1.62 mul rlineto\n",
  108. "  hpt 2 mul 0 rlineto\n",
  109. "  hpt neg vpt 1.62 mul rlineto  closepath  stroke\n",
  110. "  P  } def\n",
  111. "/S { 2 copy A C} def\n", /* Star */
  112. NULL
  113. };
  114.  
  115. #define PS_XOFF    50    /* page offset in pts */
  116. #define PS_YOFF    50
  117.  
  118. #define PS_XMAX 7200
  119. #define PS_YMAX 5040
  120.  
  121. #define PS_XLAST (PS_XMAX - 1)
  122. #define PS_YLAST (PS_YMAX - 1)
  123.  
  124. #define PS_VTIC (PS_YMAX/80)
  125. #define PS_HTIC (PS_YMAX/80)
  126.  
  127. #define PS_SC (10)                /* scale is 1pt = 10 units */
  128. #define    PS_LW (0.5*PS_SC)        /* linewidth = 0.5 pts */
  129.  
  130. #define PS_VCHAR (14*PS_SC)        /* default is 14 point characters */
  131. #define PS_HCHAR (14*PS_SC*6/10)
  132.  
  133.  
  134. PS_options()
  135. {
  136.     extern struct value *const_express();
  137.     extern double real();
  138.  
  139.     if (!END_OF_COMMAND) {
  140.         if (almost_equals(c_token,"p$ortrait")) {
  141.             ps_portrait=TRUE;
  142.              ps_eps=FALSE;
  143.             c_token++;
  144.         }
  145.         else if (almost_equals(c_token,"l$andscape")) {
  146.             ps_portrait=FALSE;
  147.              ps_eps=FALSE;
  148.             c_token++;
  149.         }
  150.          else if (almost_equals(c_token,"e$psf")) {
  151.              ps_portrait=TRUE;
  152.              ps_eps = TRUE;
  153.              c_token++;
  154.          }
  155.         else if (almost_equals(c_token,"d$efault")) {
  156.             ps_portrait=FALSE;
  157.              ps_eps=FALSE;
  158.             ps_color=FALSE;
  159.             strcpy(ps_font,"Courier");
  160.             ps_fontsize = 14;
  161.             term_tbl[term].v_char = (unsigned int)(ps_fontsize*PS_SC);
  162.             term_tbl[term].h_char = (unsigned int)(ps_fontsize*PS_SC*6/10);
  163.             c_token++;
  164.         }
  165.     }
  166.  
  167.     if (!END_OF_COMMAND) {
  168.         if (almost_equals(c_token,"m$onochrome")) {
  169.             ps_color=FALSE;
  170.             c_token++;
  171.         }
  172.         else if (almost_equals(c_token,"c$olor")) {
  173.             ps_color=TRUE;
  174.             c_token++;
  175.         }
  176.     }
  177.  
  178.     if (!END_OF_COMMAND && isstring(c_token)) {
  179.         quote_str(ps_font,c_token);
  180.         c_token++;
  181.     }
  182.  
  183.     if (!END_OF_COMMAND) {
  184.         /* We have font size specified */
  185.         struct value a;
  186.         ps_fontsize = (int)real(const_express(&a));
  187.         term_tbl[term].v_char = (unsigned int)(ps_fontsize*PS_SC);
  188.         term_tbl[term].h_char = (unsigned int)(ps_fontsize*PS_SC*6/10);
  189.     }
  190.  
  191.     sprintf(term_options,"%s %s \"%s\" %d",
  192.         ps_eps ? "eps" : (ps_portrait ? "portrait" : "landscape"),
  193.         ps_color ? "color" : "monochrome",ps_font,ps_fontsize);
  194. }
  195.  
  196.  
  197. PS_init()
  198. {
  199. struct termentry *t = &term_tbl[term];
  200. int i;
  201.     ps_page = 0;
  202.     if (!ps_eps)
  203.         fprintf(outfile,"%%!PS-Adobe-2.0\n");
  204.     else
  205.         fprintf(outfile,"%%!PS-Adobe-2.0 EPSF-2.0\n");
  206.     fprintf(outfile,"%%%%Creator: gnuplot\n");
  207.     fprintf(outfile,"%%%%DocumentFonts: %s\n", ps_font);
  208.     fprintf(outfile,"%%%%BoundingBox: %d %d ", PS_XOFF,PS_YOFF);
  209.     if (ps_portrait)
  210.         fprintf(outfile,"%d %d\n", 
  211.             (int)(xsize*(ps_eps ? 0.5 : 1.0)*(PS_XMAX)/PS_SC+0.5+PS_XOFF), 
  212.             (int)(ysize*(ps_eps ? 0.5 : 1.0)*(PS_YMAX)/PS_SC+0.5+PS_YOFF) );
  213.     else 
  214.         fprintf(outfile,"%d %d\n", 
  215.             (int)(ysize*(ps_eps ? 0.5 : 1.0)*(PS_YMAX)/PS_SC+0.5+PS_XOFF), 
  216.             (int)(xsize*(ps_eps ? 0.5 : 1.0)*(PS_XMAX)/PS_SC+0.5+PS_YOFF) );
  217.     if (!ps_eps)
  218.         fprintf(outfile,"%%%%Pages: (atend)\n");
  219.     fprintf(outfile,"%%%%EndComments\n");
  220.     fprintf(outfile,"/gnudict 40 dict def\ngnudict begin\n");
  221.     fprintf(outfile,"/Color %s def\n",ps_color ? "true" : "false");
  222.     fprintf(outfile,"/gnulinewidth %.3f def\n",PS_LW);
  223.     fprintf(outfile,"/vshift %d def\n", (int)(t->v_char)/(-3));
  224.     fprintf(outfile,"/dl {%d mul} def\n",PS_SC); /* dash length */
  225.     fprintf(outfile,"/hpt %.1f def\n",PS_HTIC/2.0);
  226.     fprintf(outfile,"/vpt %.1f def\n",PS_VTIC/2.0);
  227.     for ( i=0; PS_header[i] != NULL; i++)
  228.         fprintf(outfile,"%s",PS_header[i]);
  229.     fprintf(outfile,"end\n");
  230.     fprintf(outfile,"%%%%EndProlog\n");
  231. }
  232.  
  233.  
  234. PS_graphics()
  235. {
  236. struct termentry *t = &term_tbl[term];
  237.     ps_page++;
  238.     if (!ps_eps)
  239.         fprintf(outfile,"%%%%Page: %d %d\n",ps_page,ps_page);
  240.     fprintf(outfile,"gnudict begin\n");
  241.     fprintf(outfile,"gsave\n");
  242.     fprintf(outfile,"%d %d translate\n",PS_XOFF,PS_YOFF);
  243.     fprintf(outfile,"%.3f %.3f scale\n", (ps_eps ? 0.5 : 1.0)/PS_SC,
  244.                                          (ps_eps ? 0.5 : 1.0)/PS_SC);
  245.     if (!ps_portrait) {
  246.         fprintf(outfile,"90 rotate\n0 %d translate\n", (int)(-PS_YMAX*ysize));
  247.     }
  248.     fprintf(outfile,"0 setgray\n");
  249.     fprintf(outfile,"/%s findfont %d ",ps_font, (t->v_char) );
  250.     fprintf(outfile,"scalefont setfont\n");
  251.     fprintf(outfile,"newpath\n");
  252.     ps_path_count = 0;
  253. }
  254.  
  255.  
  256. PS_text()
  257. {
  258.     ps_path_count = 0;
  259.     fprintf(outfile,"stroke\ngrestore\nend\nshowpage\n");
  260. }
  261.  
  262.  
  263. PS_reset()
  264. {
  265.     fprintf(outfile,"%%%%Trailer\n");
  266.     if (!ps_eps)
  267.         fprintf(outfile,"%%%%Pages: %d\n",ps_page);
  268. }
  269.  
  270.  
  271. PS_linetype(linetype)
  272. int linetype;
  273. {
  274. char *line = "ba012345678"; 
  275.     fprintf(outfile,"LT%c\n", line[(linetype%9)+2]);
  276.     ps_path_count = 0;
  277. }
  278.  
  279.  
  280. PS_move(x,y)
  281. unsigned int x,y;
  282. {
  283.     fprintf(outfile,"%d %d M\n", x, y);
  284.     ps_path_count += 1;
  285. }
  286.  
  287.  
  288. PS_vector(x,y)
  289. unsigned int x,y;
  290. {
  291.     fprintf(outfile,"%d %d L\n", x, y);
  292.     ps_path_count += 1;
  293.     if (ps_path_count >= 400) {
  294.         fprintf(outfile,"currentpoint stroke moveto\n");
  295.         ps_path_count = 0;
  296.     }
  297. }
  298.  
  299.  
  300. PS_put_text(x,y,str)
  301. unsigned int x, y;
  302. char *str;
  303. {
  304. char ch;
  305.     PS_move(x,y);
  306.     if (ps_ang != 0)
  307.         fprintf(outfile,"currentpoint gsave translate %d rotate 0 0 moveto\n"
  308.             ,ps_ang*90);
  309.     putc('(',outfile);
  310.     ch = *str++;
  311.     while(ch!='\0') {
  312.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  313.             putc('\\',outfile);
  314.         putc(ch,outfile);
  315.         ch = *str++;
  316.     }
  317.     switch(ps_justify) {
  318.         case LEFT : fprintf(outfile,") Lshow\n");
  319.             break;
  320.         case CENTRE : fprintf(outfile,") Cshow\n");
  321.             break;
  322.         case RIGHT : fprintf(outfile,") Rshow\n");
  323.             break;
  324.     }
  325.     if (ps_ang != 0)
  326.         fprintf(outfile,"grestore\n");
  327.     ps_path_count = 0;
  328. }
  329.  
  330. int PS_text_angle(ang)
  331. int ang;
  332. {
  333.     ps_ang=ang;
  334.     return TRUE;
  335. }
  336.  
  337. int PS_justify_text(mode)
  338. enum JUSTIFY mode;
  339. {
  340.     ps_justify=mode;
  341.     return TRUE;
  342. }
  343.  
  344. /* postscript point routines */
  345. PS_point(x,y,number)
  346. int x,y;
  347. int number;
  348. {
  349. char *point = "PDABCTS";
  350.     number %= POINT_TYPES;
  351.      if (number < -1)
  352.         number = -1;        /* negative types are all 'dot' */
  353.     fprintf(outfile,"%d %d %c\n", x, y, point[number+1]);
  354.     ps_path_count = 0;
  355. }
  356.  
  357.